#include <errno.h>
#include <sys/stat.h>
#include <irt_syscalls.h>

int lstat(const char *name, struct stat *buf) {
  ENOSYS_IF_NULL(__nacl_irt_lstat)

  if (buf == NULL) {
    errno = EFAULT;
    return -1;
  }

  struct nacl_abi_stat nacl_buf;
  int result = __nacl_irt_lstat(name, (struct stat*) &nacl_buf);
  if (result != 0) {
    errno = __nacl_abi_errno_to_errno(result);
    return -1;
  }

  __nacl_abi_stat_to_stat (&nacl_buf, buf);
  return 0;
}
